<template lang="pug">
  .tab-1
    Table.hasTitle-table.beautiful-table(:columns="thead" :data="budgetList")
      //- .pr-24.pl-24(slot="header")
      //-   .pull-right
      //-     Button.mr-15(type="info" size="small" @click="addContact") 添加联系人
      template(slot-scope="{ row, index }" slot="action")
        Button.mr-10(type="text" size="small" @click="reviseBtn(row)") 修改
        //- Button(type="text" size="small") 删除
    Modal(v-model="reviseModal" title="客户预算")
      Form(ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110")
        FormItem.mb-5(label="今年计划：" prop="plan")
          Input(v-model="formValidate.plan" placeholder="请输入")
        FormItem.mb-5(label="今年预算：" prop="budgetDetail")
          Input(v-model="formValidate.budgetDetail" placeholder="请输入")
        FormItem.mb-5(label="过往供应商：" prop="historySuppliers")
          Input(v-model="formValidate.historySuppliers" type="textarea" placeholder="请输入")
        FormItem.mb-5(label="过往项目：" prop="historyProjects")
          Input(v-model="formValidate.historyProjects" type="textarea" placeholder="请输入")
      template(slot="footer")
        Button(type="info" @click="handleSubmit('formValidate')") 提交
        Button(@click="reviseModal = false") 取消
</template>

<script>
import HRDCCustomerApi from '@/api/HRDCCustomer.api.js'

export default {
  props: {
    budgetList: Array
  },
  data () {
    return {
      isCheck: true,
      reviseModal: false,
      thead: [
        {
          title: '新增时间',
          minWidth: 120,
          render: (h, params) => {
            let row = params.row
            let times = ''
            if (row.createTime) {
              times = row.createTime.slice(0, 19).replace(/T/g, ' ')
            }
            return h('span', times)
          }
        },
        {
          title: '今年计划',
          minWidth: 120,
          key: 'plan'
        },
        {
          title: '今年预算',
          minWidth: 100,
          key: 'budgetDetail'
        },
        {
          title: '过往供应商',
          minWidth: 110,
          key: 'historySuppliers'
        },
        {
          title: '过往项目',
          minWidth: 110,
          key: 'historyProjects'
        },
        {
          title: '记录销售',
          minWidth: 100,
          key: 'createrName'
        },
        {
          title: '操作',
          minWidth: 140,
          slot: 'action'
        }
      ],
      formValidate: {
        // plan: '',
        // budgetDetail: '',
        // historySuppliers: '',
        // historyProjects : '',
      },
      ruleValidate: {
        plan: [
          { required: true, message: '计划不能为空', trigger: 'blur' }
        ],
        budgetDetail: [
          { required: true, message: '预算不能为空', trigger: 'blur' }
        ],
        historySuppliers: [
          { required: true, message: '过往供应商不能为空', trigger: 'blur' }
        ],
        historyProjects: [
          { required: true, message: '过往项目不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    reviseBtn (obj) {
      this.formValidate = obj
      this.reviseModal = true
    },
    handleSubmit (name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.postBudget()
        } else {
          this.$Message.warning('有必填项未填写！')
        }
      })
    },
    // 修改预算
    postBudget () {
      HRDCCustomerApi.PostBudget(this.formValidate).then(res => {
        if (res.data.success) {
          this.$Message.success(res.data.message)
          this.reviseModal = false
          this.$emit('get-list')
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    }
  }
}
</script>

<style>

</style>
